
/**
	AUTHOR		: VEERU
	DATE		: FEB 11th 2004
	DESCRIPTION	: THIS PROCEDURE IS USED TO UPDATE THE USER DEFINED FIELD NAMES THAT ARE USED FOR PROJECT SETUP.
*/

ALTER  PROC SP_SAVE_USER_DEFINED_FIELD_NAMES

-- INPUT PARAMETERS
@TABLENAME VARCHAR(100),
@USERLIST1 VARCHAR(100), 
@USERLIST2 VARCHAR(100), 
@USERLIST3 VARCHAR(100), 
@USERDATE1 VARCHAR(100), 
@USERDATE2 VARCHAR(100), 
@USERTXT1  VARCHAR(100), 
@USERTXT2  VARCHAR(100), 
@USERTXT3  VARCHAR(100), 
@USERTXT4  VARCHAR(100), 
@USERTXT5  VARCHAR(100),
@USERLIST4 VARCHAR(100), 
@USERLIST5 VARCHAR(100), 
@USERLIST6 VARCHAR(100), 
@USERDATE3 VARCHAR(100), 
@USERDATE4 VARCHAR(100), 
@USERTXT6  VARCHAR(100), 
@USERTXT7  VARCHAR(100), 
@USERTXT8  VARCHAR(100), 
@USERTXT9  VARCHAR(100), 
@USERTXT10 VARCHAR(100)


AS 
BEGIN
	DECLARE @DB_USERLIST1 VARCHAR(100) 
	DECLARE @DB_USERLIST2 VARCHAR(100) 
	DECLARE @DB_USERLIST3 VARCHAR(100) 
	DECLARE @DB_USERDATE1 VARCHAR(100) 
	DECLARE @DB_USERDATE2 VARCHAR(100) 
	DECLARE @DB_USERTXT1  VARCHAR(100) 
	DECLARE @DB_USERTXT2  VARCHAR(100) 
	DECLARE @DB_USERTXT3  VARCHAR(100) 
	DECLARE @DB_USERTXT4  VARCHAR(100) 
	DECLARE @DB_USERTXT5  VARCHAR(100) 
	DECLARE @DB_USERLIST4 VARCHAR(100) 
	DECLARE @DB_USERLIST5 VARCHAR(100) 
	DECLARE @DB_USERLIST6 VARCHAR(100) 
	DECLARE @DB_USERDATE3 VARCHAR(100) 
	DECLARE @DB_USERDATE4 VARCHAR(100) 
	DECLARE @DB_USERTXT6  VARCHAR(100) 
	DECLARE @DB_USERTXT7  VARCHAR(100) 
	DECLARE @DB_USERTXT8  VARCHAR(100) 
	DECLARE @DB_USERTXT9  VARCHAR(100) 
	DECLARE @DB_USERTXT10 VARCHAR(100) 
	
    -- WHEN NO PR0JECTS ARE AVAILABLE INSERTING DUMMY PROJECT FOR USER DEFINED FIELD NAMES
	IF ( ( SELECT COUNT(*) FROM PROJSETUP ) = 0 )
	BEGIN
		INSERT INTO PROJSETUP( PROJNAME, USERLIST1, USERLIST2, USERLIST3, USERDATE1, USERDATE2, USERTXT1, USERTXT2, USERTXT3, USERTXT4, USERTXT5, USERLIST4, USERLIST5, USERLIST6, USERDATE3, USERDATE4, USERTXT6, USERTXT7, USERTXT8, USERTXT9, USERTXT10, PROJDISABLED ) VALUES ( '',@USERLIST1, @USERLIST2, @USERLIST3, @USERDATE1, @USERDATE2, @USERTXT1, @USERTXT2, @USERTXT3, @USERTXT4, @USERTXT5, @USERLIST4, @USERLIST5, @USERLIST6, @USERDATE3, @USERDATE4, @USERTXT6, @USERTXT7, @USERTXT8, @USERTXT9, @USERTXT10, 0 )	
	END


	SELECT  @DB_USERLIST1  = USERLIST1, 
		@DB_USERLIST2  = USERLIST2,   
		@DB_USERLIST3  = USERLIST3,   
		@DB_USERDATE1  = USERDATE1,   
		@DB_USERDATE2  = USERDATE2,   
		@DB_USERTXT1   = USERTXT1,   
		@DB_USERTXT2   = USERTXT2,   
		@DB_USERTXT3   = USERTXT3,  
		@DB_USERTXT4   = USERTXT4,  
		@DB_USERTXT5   = USERTXT5,
		@DB_USERLIST4  = USERLIST4, 
		@DB_USERLIST5  = USERLIST5,   
		@DB_USERLIST6  = USERLIST6,   
		@DB_USERDATE3  = USERDATE3,   
		@DB_USERDATE4  = USERDATE4,   
		@DB_USERTXT6   = USERTXT6,   
		@DB_USERTXT7   = USERTXT7,   
		@DB_USERTXT8   = USERTXT8,  
		@DB_USERTXT9   = USERTXT9,  
		@DB_USERTXT10  = USERTXT10 FROM PROJSETUP WHERE PROJID = ( SELECT MAX(PROJID) FROM PROJSETUP )

	-- UPDATING USER DEFINED FIELD NAMES IN FCUENTRYVAL TABLE
	IF ( LTRIM( RTRIM( @USERLIST1) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERLIST1 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERLIST1 WHERE ENTRYNAME = @DB_USERLIST1 AND TABLENAME = @TABLENAME 	
	END	
	--
	IF ( LTRIM( RTRIM( @USERLIST2) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERLIST2 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERLIST2 WHERE ENTRYNAME = @DB_USERLIST2 AND TABLENAME = @TABLENAME 
	END
	--	
	IF ( LTRIM( RTRIM( @USERLIST3) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERLIST3 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERLIST3 WHERE ENTRYNAME = @DB_USERLIST3 AND TABLENAME = @TABLENAME 
	END
	--
	IF ( LTRIM( RTRIM( @USERDATE1 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERDATE1 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERDATE1 WHERE ENTRYNAME = @DB_USERDATE1 AND TABLENAME = @TABLENAME 
	END
	--
	IF ( LTRIM( RTRIM( @USERDATE2 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERDATE2 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERDATE2 WHERE ENTRYNAME = @DB_USERDATE2 AND TABLENAME = @TABLENAME 
	END
	--
	IF ( LTRIM( RTRIM( @USERTXT1 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERTXT1 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN	
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERTXT1 WHERE ENTRYNAME = @DB_USERTXT1 AND TABLENAME = @TABLENAME
	END
	--
	IF ( LTRIM( RTRIM( @USERTXT2 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERTXT2 AND TABLENAME = @TABLENAME 
	END

	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERTXT2 WHERE ENTRYNAME = @DB_USERTXT2 AND TABLENAME = @TABLENAME 
	END
	--	
	IF ( LTRIM( RTRIM( @USERTXT3 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERTXT3 AND TABLENAME = @TABLENAME 
	END

	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERTXT3 WHERE ENTRYNAME = @DB_USERTXT3 AND TABLENAME = @TABLENAME 
	END
	--
	IF ( LTRIM( RTRIM( @USERTXT4 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERTXT4 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERTXT4 WHERE ENTRYNAME = @DB_USERTXT4 AND TABLENAME = @TABLENAME 	
	END
	--
	IF ( LTRIM( RTRIM( @USERTXT5 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERTXT5 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERTXT5 WHERE ENTRYNAME = @DB_USERTXT5 AND TABLENAME = @TABLENAME
	END

	IF ( LTRIM( RTRIM( @USERLIST4) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERLIST4 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERLIST4 WHERE ENTRYNAME = @DB_USERLIST4 AND TABLENAME = @TABLENAME 	
	END	
	--
	IF ( LTRIM( RTRIM( @USERLIST5) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERLIST5 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERLIST5 WHERE ENTRYNAME = @DB_USERLIST5 AND TABLENAME = @TABLENAME 
	END
	--	
	IF ( LTRIM( RTRIM( @USERLIST6) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERLIST6 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERLIST6 WHERE ENTRYNAME = @DB_USERLIST6 AND TABLENAME = @TABLENAME 
	END
	--
	IF ( LTRIM( RTRIM( @USERDATE3 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERDATE3 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERDATE3 WHERE ENTRYNAME = @DB_USERDATE3 AND TABLENAME = @TABLENAME 
	END
	--
	IF ( LTRIM( RTRIM( @USERDATE4 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERDATE4 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERDATE4 WHERE ENTRYNAME = @DB_USERDATE4 AND TABLENAME = @TABLENAME 
	END
	--
	IF ( LTRIM( RTRIM( @USERTXT6 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERTXT6 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN	
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERTXT6 WHERE ENTRYNAME = @DB_USERTXT6 AND TABLENAME = @TABLENAME
	END
	--
	IF ( LTRIM( RTRIM( @USERTXT7 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERTXT7 AND TABLENAME = @TABLENAME 
	END

	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERTXT7 WHERE ENTRYNAME = @DB_USERTXT7 AND TABLENAME = @TABLENAME 
	END
	--	
	IF ( LTRIM( RTRIM( @USERTXT8 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERTXT8 AND TABLENAME = @TABLENAME 
	END

	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERTXT8 WHERE ENTRYNAME = @DB_USERTXT8 AND TABLENAME = @TABLENAME 
	END
	--
	IF ( LTRIM( RTRIM( @USERTXT9 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERTXT9 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERTXT9 WHERE ENTRYNAME = @DB_USERTXT9 AND TABLENAME = @TABLENAME 	
	END
	--
	IF ( LTRIM( RTRIM( @USERTXT10 ) ) = '' )
	BEGIN
		DELETE FROM FCUENTRYVAL WHERE ENTRYNAME = @DB_USERTXT10 AND TABLENAME = @TABLENAME 
	END
	ELSE
	BEGIN
		UPDATE FCUENTRYVAL SET ENTRYNAME = @USERTXT10 WHERE ENTRYNAME = @DB_USERTXT10 AND TABLENAME = @TABLENAME
	END

	
	-- UPDATING USER DEFINED FIELD NAMES IN PROJSETUP TABLE

	UPDATE PROJSETUP SET USERLIST1 = @USERLIST1, USERLIST2 = @USERLIST2, USERLIST3 = @USERLIST3, USERDATE1 = @USERDATE1, USERDATE2 = @USERDATE2, USERTXT1 = @USERTXT1, USERTXT2 = @USERTXT2, USERTXT3 = @USERTXT3, USERTXT4 = @USERTXT4, USERTXT5  = @USERTXT5, 
			     USERLIST4 = @USERLIST4, USERLIST5 = @USERLIST5, USERLIST6 = @USERLIST6, USERDATE3 = @USERDATE3, USERDATE4 = @USERDATE4, USERTXT6 = @USERTXT6, USERTXT7 = @USERTXT7, USERTXT8 = @USERTXT8, USERTXT9 = @USERTXT9, USERTXT10  = @USERTXT10  


END

